<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="../js/resources/image-preload-helper.js"></script>
<style type="text/css">
</style>
</head>
<body>
<p id="description"></p>
<p><a href=https://bugs.webkit.org/show_bug.cgi?id=100550>Bug 100550</a></p>
<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
  <defs>
    <cursor id="greenbox" xlink:href="resources/greenbox.png" x="0" y="0"/>
  </defs>
</svg>
<div id="test-container">
  <div>Implicit default cursor</div>
  <div style='cursor: default'>Explicit default</div>
  <div style='cursor: auto'>Explicit auto</div>
  <div style='cursor: none'>No cursor</div>
  <div style='cursor: pointer'>Pointer</div>
  <div style='cursor: grab'>grab</div>
  <div style='cursor: grabbing'>grabbing</div>
  <div style='cursor: -webkit-grab'>-webkit-grab</div>
  <div style='cursor: -webkit-grabbing'>-webkit-grabbing</div>
  <div style='cursor: url(resources/greenbox.png), hand'>Existing 25x25 image</div>
  <div style='cursor: url(doesntexist_FAIL.png), pointer'>Invalid URL with fallback to pointer</div>
  <div style='cursor: url(doesntexist_FAIL.png), url(resources/greenbox.png), pointer'>Invalid with fallback to 25x25 image</div>
  <div style='cursor: url(resources/greenbox.png) 0 0, pointer'>Image with explicit hot spot at (0,0)</div>
  <div style='cursor: url(resources/greenbox.png) 20 10, pointer'>Image with explicit hot spot at (20,10)</div>
  <div style='cursor: url(resources/greenbox.png) -1 -1, pointer'>Image with explicit hot spot at (-1,-1)</div>
  <div style='cursor: url(resources/greenbox.png) 30 30, pointer'>Image with explicit hot spot outside image at (30,30)</div>
  <div style='cursor: url(resources/greenbox-hotspot5-4.cur), pointer'>Image with implicit hot spot at (5,4)</div>
  <div style='cursor: url(resources/greenbox-hotspot5-4.cur) 20 10, pointer'>Image with explicit hot spot at (20,10) overriding implicit hot spot</div>
  <div style='cursor: url(resources/greenbox-hotspot35-4.cur), pointer'>Image with implicit hot spot outside image at (35,4)</div>
  <div style='cursor: url(resources/onload-image.png), pointer'>Over large image with fallback to pointer</div>
  <div style='cursor: url(#greenbox), pointer'>Local element reference</div>
  <div style='cursor: url(mouse-cursor_FAIL.html), url(unknown-scheme:cursor_FAIL.png), pointer'>Multiple invalid cursors with fallback to pointer</div>
  <div style='cursor: url(#nonexistent_FAIL), pointer'>Nonexistent local element reference with fallback to pointer</div>
  <div><a href='#'>A link with default cursor</a></div>
  <div style='cursor: wait'><a href='#'>Link with default cursor overriding wait</a></div>
  <div style='cursor: wait'><div style='cursor: doesntexist'>Wait cursor which should not be affected by unknown cursor rule</div></div>
</div>
<br/>
<div id="console"></div>
<script>

var testContainer = document.getElementById('test-container');
    
function runTests() {
    // Can't do anything useful here without eventSender
    if (window.eventSender) {
        var nodesToTest = document.querySelectorAll('#test-container > div');
        for (var i = 0; i < nodesToTest.length; i++) {
            var node = nodesToTest[i];
            debug('TEST CASE: ' + node.textContent);

            // Make sure the node is visible and move the mouse over top of it.
            document.documentElement.scrollTop = node.offsetTop - 50;
            eventSender.mouseMoveTo(node.offsetLeft + 3, node.offsetTop - document.documentElement.scrollTop + 3);

            // Get details of the current mouse cursor.
            // Note that we could return structured data which we then validate, but that's a lot more
            // work and is redundant with relying on the expected output anyway.  Better to just dump
            // it and inspect that it matches the description.
            debug('Cursor Info: ' + internals.getCurrentCursorInfo());
            debug('');
        }
        // This text is redundant with the test output - hide it
        testContainer.style.display = 'none';
    }
    
    finishJSTest();
}

description("Test that mouse cursors are applied correctly.");

if (!window.eventSender) {
    testFailed('This test requires DumpRenderTree');
}

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
    window.jsTestIsAsync = true;
}

// Now wait for each image to load or fail to load before starting tests.
// Without this we can get null images in the cursors - eg. no known size.
preloadImagesFromStyle(testContainer, 9, runTests, /(#greenbox|_FAIL)/);

</script>
</body>
</html>
